/*    */ package com.newcrm.businessarchives;
/*    */ 
/*    */ import com.newcrm.bean.CaptchaEntity;
/*    */ import java.util.Date;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ 
/*    */ public class CaptchaEntityManager
/*    */ {
/* 11 */   private static CaptchaEntityManager captchaEntityManager = null;
/*    */ 
/* 13 */   private Map<String, CaptchaEntity> entitys = new HashMap();
/*    */   public static final String GUANGZHOU = "gz";
/*    */   public static final String SHENZHENG = "sz";
/*    */ 
/*    */   public static CaptchaEntityManager getInstance()
/*    */   {
/* 23 */     if (captchaEntityManager == null) {
/* 24 */       captchaEntityManager = new CaptchaEntityManager();
/*    */     }
/*    */ 
/* 27 */     return captchaEntityManager;
/*    */   }
/*    */ 
/*    */   public CaptchaEntity get(String key, boolean isReload) {
/* 31 */     if ((key == null) || (key.trim().length() == 0)) {
/* 32 */       return null;
/*    */     }
/*    */ 
/* 35 */     CaptchaSearchEngine searchEngine = null;
/* 36 */     if ("gz".equals(key)) {
/* 37 */       searchEngine = new GuangzhouSearchEngine();
/*    */     }
/* 39 */     if ("sz".equals(key)) {
/* 40 */       searchEngine = new ShenzhenSearchEngine();
/*    */     }
/* 42 */     if (searchEngine == null) {
/* 43 */       return null;
/*    */     }
/* 45 */     if (isReload) {
/* 46 */       CaptchaEntity captchaEntity = searchEngine.downloadImage();
/* 47 */       this.entitys.put(key, captchaEntity);
/* 48 */       return captchaEntity;
/*    */     }
/*    */ 
/* 51 */     CaptchaEntity captchaEntity = (CaptchaEntity)this.entitys.get(key);
/* 52 */     if (captchaEntity == null) {
/* 53 */       captchaEntity = searchEngine.downloadImage();
/* 54 */       if (captchaEntity != null) {
/* 55 */         this.entitys.put(key, captchaEntity);
/* 56 */         return captchaEntity;
/*    */       }
/*    */ 
/*    */     }
/*    */ 
/* 61 */     if (captchaEntity == null) {
/* 62 */       return null;
/*    */     }
/*    */ 
/* 67 */     Date current = new Date();
/* 68 */     long timeout = (current.getTime() - captchaEntity.createDate.getTime()) / 1000L;
/* 69 */     if (timeout > 60L)
/*    */     {
/* 71 */       captchaEntity = searchEngine.downloadImage();
/* 72 */       this.entitys.put(key, captchaEntity);
/* 73 */       return captchaEntity;
/*    */     }
/*    */ 
/* 76 */     return captchaEntity;
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.CaptchaEntityManager
 * JD-Core Version:    0.6.1
 */